"use client";
import { Button, Form, Input, InputNumber, message, Typography } from "antd";
import React, { useState } from "react";
import { aiGenerateQuestionUsingPost } from "@/api/questionController";
import "./index.css";

interface Props {}

/**
 * AI 生成题目页面
 * @param props
 * @constructor
 */
const AiGenerateQuestionPage: React.FC<Props> = (props) => {
    const [form] = Form.useForm();
    const [loading, setLoading] = useState(false);

    /**
     * 提交
     *
     * @param values
     */
    const doSubmit = async (values: API.QuestionAIGenerateRequest) => {
        const hide = message.loading("正在操作");
        setLoading(true);
        try {
            await aiGenerateQuestionUsingPost(values);
            hide();
            message.success("操作成功");
        } catch (error: any) {
            hide();
            message.error("操作失败，" + error.message);
        }
        setLoading(false);
    };

    return (
        <div id="aiGenerateQuestionPage">
            <h2>AI 生成题目</h2>
            <Form form={form} style={{ marginTop: 24 }} onFinish={doSubmit}>
                <Form.Item label="题目方向" name="questionType">
                    <Input placeholder="比如 Java" />
                </Form.Item>
                <Form.Item label="题目数量" name="number">
                    <InputNumber defaultValue={10} max={30} min={1} />
                </Form.Item>
                <Form.Item>
                    <Button
                        loading={loading}
                        style={{ width: 180 }}
                        type="primary"
                        htmlType="submit"
                    >
                        提交
                    </Button>
                </Form.Item>
                {/* 新增提示信息 */}
                <Form.Item>
                    <Typography.Text type="secondary" style={{ fontSize: 14 }}>
                        注意：<br />
                        1. 题目数量只能在1-30之间，建议多次生成少量题目；<br />
                        2. 由于DeepSeek模型生成速度较慢，有时需要较长等待时间，提交后请稍后到题目列表查看；<br />
                        3. 由于Tokens数量有限，测试时请手下留情，作者荷包不太够~
                    </Typography.Text>
                </Form.Item>
            </Form>
        </div>
    );
};
export default AiGenerateQuestionPage;